import pytest
import config
from api.ihrm_api import IhrmApi
from common.header_util import HeaderUtil
from common.hm03_assert import Ihrmcommon
from common.mysql_tool import DBUtil
from common.read_data import read_ihrmAdd


class TestIhrmAdd:
    # 定义属性类
    header = None

    @classmethod
    def setup_class(cls):
        cls.header = HeaderUtil.loginApi()

    # 每条用例测试前SQL删除手机号
    @classmethod
    def setup(cls):
        del_sql = f"DELETE from bs_user where mobile = '{config.TEL}';"
        DBUtil.uid_db(del_sql)

    # 每条用例测试后SQL删除手机号
    @classmethod
    def teardown(cls):
        del_sql = f"DELETE from bs_user where mobile = '{config.TEL}';"
        DBUtil.uid_db(del_sql)

    @pytest.mark.parametrize("json_data,status_code,success,code,message", read_ihrmAdd())
    # 测试方法
    def test(self, json_data, status_code, success, code, message):
        # 添加员工
        add_result = IhrmApi.add(self.header, json_data)
        # print(add_result.json())
        Ihrmcommon.add_assert(add_result, status_code, success, code, message)
